package cn.com.pagoda.ideplugin.service.pwdGen.service;

import cn.com.pagoda.ideplugin.service.pwdGen.service.impl.LowerCasePasswordGenerator;
import cn.com.pagoda.ideplugin.service.pwdGen.service.impl.NumericPasswordGenerator;
import cn.com.pagoda.ideplugin.service.pwdGen.service.impl.SpecialCharacterPasswordGenerator;
import cn.com.pagoda.ideplugin.service.pwdGen.service.impl.UpperCasePasswordGenerator;

/**
 * 密码类型枚举
 * @author Mch
 * @date 2023-05-27
 */
public enum PasswordType
{
    LOWER("LOWER"), UPPER("UPPER"), NUMBER("NUMBER"), SPECIAL("SPECIAL");


    private String name;

    PasswordType(String name){
        this.name = name;
    }

    private static PasswordType getType(String name){
        for (PasswordType passwordType : PasswordType.values() ) {
            if(name.equals(passwordType.name())){
                return passwordType;
            }
        }
        return null;
    }

    private static PasswordGenerator getGenerator(PasswordType passwordType){
        if(passwordType == null){
            throw new RuntimeException("无效的类型");
        }
        switch (passwordType){
            case LOWER:
                return new LowerCasePasswordGenerator();
            case UPPER:
                return new UpperCasePasswordGenerator();
            case NUMBER:
                return new NumericPasswordGenerator();
            case SPECIAL:
                return new SpecialCharacterPasswordGenerator();
            default:
                throw new RuntimeException("无效的类型");
        }
    }


    public static PasswordGenerator trans(String name){
        return getGenerator(getType(name));
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
